/////////////////
//  PREAMBLE  //
////////////////


/*	program:	Analysis-4-Antebellum.do
	author:		David Bateman */

******************************************************************************/
/***                                                                        ***/
/*** File opens opens antebellum-voting.dta, merges this with census data   ***/
/*** corrects a few observations, and then produces the analysis of turnout ***/
/*** and party voting in antebellum elections shown in the main text and    ***/
/*** supplemental material.                                                 ***/
/***                                                                        ***/
/*** Since we have census estimates of the size of the adult male           ***/
/*** population, we can calculate turnout directly. To compare with early   ***/
/*** Republic results I also calculate a z-score as a standardized measure  ***/
/*** of turnout. The score is calculated for each place/office across all   ***/
/*** counties.                                                              ***/
/***                                                                        ***/
/******************************************************************************/

cd "..\..\Dataverse\"
use "Data\antebellum-voting.dta", clear

*** Merge in census data
merge m:1 county state year using "Data\adult-male-census-counties.dta" 
keep if _merge==3
drop _merge 

*** Correct Baltimore observation. See notes in antebellum-voting.dta for other corrections.
*** ICPSR congressional vote for Baltimore in 1824, 26, 29, 31 and 59 include both county and city
*** Accommodate this by setting the county population as the combined city+county
qui foreach x of varlist totpop- b21m {
	*** summ city for 1824 congressional
	summ `x' if county==5100 & state==52 & year==1824 & office==3
	loc a = r(max)
	*** replace county with city and county for 1824 congressional
	replace `x' = `x'+`a' if county==50 & state==52 & year==1824 & office==3
	summ `x' if county==5100 & state==52 & year==1826
	loc b = r(max)
	replace `x' = `x'+`b' if county==50 & state==52 & year==1826 & office==3
	summ w21m if county==5100 & state==52 & year==1829
	loc c = r(max)
	replace `x' = `x'+`c' if county==50 & state==52 & year==1829 & office==3
	summ `x' if county==5100 & state==52 & year==1831
	loc d = r(max)
	replace `x' = `x'+`d' if county==50 & state==52 & year==1831 & office==3
	summ `x' if county==5100 & state==52 & year==1859
	loc e = r(max)
	replace `x' = `x'+`e' if county==50 & state==52 & year==1859 & office==3
}

*** Generate a turnout calculation. This is greater than 100 in fast growing
*** counties or where there is a data error. Some of these errors have been identified
*** and corrected or dropped (see notes)
gen turnout_1		= round(total/w21m*100,2) if (office==2 | office==1)
replace turnout_1	= round((total/membersMC)/w21m*100,2) if (office==3 )

*** Merge in reduced suffrage database. This will be used for supplemental material.
rename state icpsrstate
merge m:1 icpsrstate year using "Data\Suffrage-Reduced.dta", gen(merge1)
keep if merge1==3
drop merge1

gen category_prop_tax = 0 if whnb_property_effective==0 & whnb_taxpayer==0
replace category_prop_tax = 1 if whnb_taxpayer==1 
replace category_prop_tax = 2 if whnb_property_effective==1 

capture label drop category_prop_tax
label define category_prop_tax 0 "Residency"
label define category_prop_tax 1 "Tax", add
label define category_prop_tax 2 "Property", add
label values category_prop_tax category_prop_tax


*** Generate time variables
gen time = year-1787
gen time_2 = time^2
gen decade = int(year/10)*10

*** When did suffrage reform go into effect? Three states made major revisions in
*** antebellum era: Virginia, Rhode Island, and Louisiana. North Carolina did as 
*** well, but only for state senate elections not in the ICPSR voting data.
gen reform 		= . 
replace reform	= -47361 if icpsrstate==40
replace reform	= -42643 if icpsrstate==5 
replace reform	= -41637 if icpsrstate==45 
*** Generate a variable indicating which states made a substantial change during antebellum
gen refState	= (icpsrstate==45 | icpsrstate==40 | icpsrstate==5)

*** Identify states as high, medium, or low thresholds, including dates of reform
gen category 	 = 1 if (date1<-57351) & icpsrstate==52 // Amendment passed second time on 23rd Dec 1803
replace category = 1 if (date1<-51683) & icpsrstate==1 	// Constitution ratified on first Monday of Oct 1818. In Nov. 1817 a modification of the existing election law was passed, repealing the "stand-up" law. A constitutional convention would be called in 1818 on a broad franchise.
replace category = 1 if (date1<-50344) & icpsrstate==13	// Constitution ratified in January 1822 and went into effect on Dec 31 1822. Suffrage went into effect 1st Monday of March 1822
replace category = 1 if (date1<-50618) & icpsrstate==3 	// Constitutional amendments ratified in April/May of 1821. Presented to General Court on May 31 and certified May 24
replace category = 1 if (date1<-55563) & icpsrstate==12	// Statute altering qualifications enacted on Nov 16 - "from and after the passing of this act."
replace category = 2 if (date1<-54434) & icpsrstate==48	// Constitutional amendment ratified on December 19, 1810.
replace category = 1 if (date1<-61197) & icpsrstate==11	// Constitution goes into effect on June 12, 1792.
replace category = 1 if (date1<-39800) & icpsrstate==40 // Constitution went into effect on January 12, 1851
replace category = 2 if (date1<-47300) & icpsrstate==40 // Constitution ratified and went into effect on July 1 1830
replace category = 2 if (date1<-42643) & icpsrstate==5	// New (non-Dorrite) constitution was proclaimed in January and went into effect in May 1843. But for elections went into effect in April.
replace category = 1 if (date1>=-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace category = 1 if (date1<-41637) & icpsrstate==45	// Constitution went into effect in January 1846
replace category = 0 if category==.

label define category 2 "High Qualification" 1 "Medium Qualification"  0 "Low Qualification"
label values category category

					
*** Generate a Presidential election year variable
gen pres_election = 1 if year==1794 | year==1800 | year==1804 ///
| year==1808 | year==1812 | year==1816 | year==1820 ///
| year==1824 | year==1828 | year==1832 | year==1836 ///
| year==1840 | year==1844 | year==1848 | year==1852 ///
| year==1856 | year==1860
replace pres_election = 0 if pres_election!=1

*** The panel structure is set at the county level.
egen group = group(icpsrstate county)
xtset group

*** Generate the standardized turnout measure (z-score), for all elections held
*** in that county across its history
gen totalNew = total/membersMC
tempvar a b 
bys group (date1): egen `a' = mean(totalNew)
bys group (date1): egen `b' = sd(totalNew)
bys group (date1): gen zvote = (totalNew-`a')/`b'

*** Estimate a series of turnout models. The first is of our turnout estimate using
*** adult white men. The second uses the standardized turnout measure. The next three
*** look at the specific reforming states.
eststo drop est*
eststo tn1: xtreg turnout i.category i.pres_election i.decade , fe cluster(icpsrstate)
estadd local ctrls "Yes"
estadd local fixed "Yes"
eststo tn2: xtreg zvote i.category i.pres_election i.decade gained lost, fe cluster(icpsrstate)
estadd local ctrls "Yes"
estadd local fixed "Yes"
eststo tn3: xtreg turnout i.category i.pres_election if icpsrstate==40, fe robust
estadd local fixed "Yes"
eststo tn4: xtreg turnout i.category i.pres_election if icpsrstate==5, fe robust
estadd local fixed "Yes"
eststo tn5: xtreg turnout i.category i.pres_election if icpsrstate==45, fe robust
estadd local fixed "Yes"

*** Identical models as above, but using tax or property qualification rather than the
*** more accurate high/medium/low threshold
eststo suppl_tax_prop_1: xtreg turnout i.category_prop_tax i.pres_election i.decade , fe cluster(icpsrstate)
eststo suppl_tax_prop_2: xtreg zvote i.category_prop_tax i.pres_election i.decade gained lost, fe cluster(icpsrstate)

*** Create a series of graphs showing turnout across reforming and other states before
*** and after reform
preserve
	drop group
	gen group 		= state
	replace group	= "All Other States" if refState==0 

	drop if turnout>=125 

	** Different discontinuity graphs: one with Virginia's reform in 1830 the other in 1850
	tabulate icpsrstate, gen(state)
	gen year_zero = .
	bys icpsrstate (date1): replace year_zero = date1 - reform
	replace year_zero=. if icpsrs==40 & date1>=-39800
	gen treatment = year_zero>=0

	drop year_zero treatment
	gen year_zero = .
	replace reform = -40000 if icpsrstate==40
	bys icpsrstate (date1): replace year_zero = date1 - reform
	replace year_zero=. if icpsrs==40 & date1<=-47361
	gen treatment = year_zero>=0

	regress turnout i.treatment##c.year_zero if refState!=0 & turnout<=100
	predict double yhatm1 if e(sample)
	tw (scatter turnout year_zero if  year_zero>=-4000 & year_zero<=4000 & turnout<=100, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
		(line yhatm1 year_zero if year_zero<0 & year_zero>=-4000 & turnout<=100, clcol(black))	///
		(line yhatm1 year_zero if year_zero>=0 & year_zero<=4000 & turnout<=100, clcol(black)), ///
			yline(0 100, lw(thin) lc(gs14)) xline(0, lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 100)) ylabel(0(20)100, angle(h) labsize(vsmall) nogrid) ///
			xlab(-3650 "-10" -2920 "-8" -2190 "-6" -1460 "-4" -730 "-2" 0 "0"	///
				  730 "2" 1460 "4" 2190 "6" 2920 "8" 3650 "10" , labsize(vsmall) format(%tdCCYY)) ///
			xtitle("Years from reform", size(small) col(black))	ytitle("Turnout (% of White Men +21)", size(vsmall))	///
			title("Turnout", size(small) col(black) box bexpand) note("") legend(off) name(combined_turnout, replace)
	
	
	levelsof group, local(levels)
	foreach x in `levels' {
		local y = subinstr("`x'"," ","",.) 
		* trim outliers for graphing purposes
		
		di "`x'"
		qui summ reform if group=="`x'"
		local k = r(min)
		if "`x'" == "Rhode Island"  {
			tw (scatter turnout date1 if group=="`x'", msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci turnout date1 if category==2 & group=="`x'", clcol(black))	///
				(lpolyci turnout date1 if category==1 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14)) xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) fxsize(35) yscale(range(0 125)) ylabel(0(25)125, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Virginia" {
			tw (scatter turnout date1 if group=="`x'", msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci turnout date1 if category==2 & group=="`x'", clcol(black))	///
				(lpolyci turnout date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci turnout date1 if category==0 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14)) xline(-47361 -39800, lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 125)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Louisiana" {
			tw (scatter turnout date1 if group=="`x'", msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci turnout date1 if category==1 & group=="`x'", clcol(black))	///
				(lpolyci turnout date1 if category==0 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14))	xline(`k', lw(thin) lp(dash) lc(black))			///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 125)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else {
			tw (scatter turnout date1 if group=="`x'", msy(o) jitter(.8) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci turnout date1 if category==0 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14)) 				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 125)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}	

	}

restore
graph combine RhodeIsland Virginia Louisiana AllOtherStates, cols(4) imargin(none) ///
		graphreg(col(white)) xcommon l1title("Turnout (% of White Men +21)", size(vsmall)) 	///
		title("Turnout", size(small) col(black)) name(antebellum_states_turnout, replace)

***********************	 	Party Vote Share 	*********************************
*** For party voting, I only use data after the creation of the Democratic party 
*** and before the total collapse of the second party system. Otherwise, the analyses
*** have the same structure as above.
eststo dem_antebellum: xtreg dem_vshare i.category i.decade if year>=1828 & year<=1858, fe cluster(icpsrstate)
estadd local ctrls "Yes"
estadd local fixed "Yes"
eststo dem_va: xtreg dem_vshare i.category if icpsrstate==40 & year>=1828 & year<=1858, fe robust
estadd local ctrls "No"
estadd local fixed "Yes"
eststo dem_ri: xtreg dem_vshare i.category if icpsrstate==5 & year>=1828 & year<=1858, fe robust
estadd local ctrls "No"
estadd local fixed "Yes"
eststo dem_la: xtreg dem_vshare i.category if icpsrstate==45 & year>=1828 & year<=1858, fe robust
estadd local ctrls "No"
estadd local fixed "Yes"

eststo suppl_tax_prop_3: xtreg dem_vshare i.category_prop_tax i.decade if year>=1828 & year<=1858, fe cluster(icpsrstate)


preserve
	drop group
	gen group 		= state
	replace group	= "All Other States" if refState==0 

	drop if year==1823 | (dem_vshare>100 & dem_vshare!=.) | year==1860

	** Two separate discontinuity graphs: one with Virginia's reform in 1830 the other in 1850
	tabulate icpsrstate, gen(state)
	gen year_zero = .
	bys icpsrstate (date1): replace year_zero = date1 - reform
	replace year_zero=. if icpsrs==40 & date1>=-39800
	gen treatment = year_zero>=0

	drop year_zero treatment
	gen year_zero = .
	replace reform = -40000 if icpsrstate==40
	bys icpsrstate (date1): replace year_zero = date1 - reform
	replace year_zero=. if icpsrs==40 & date1<=-47361
	gen treatment = year_zero>=0

	regress dem_vshare i.treatment##c.year_zero if refState!=0  & year>=1834 & year<=1857 
	predict double yhatm1 if e(sample)
	tw (scatter dem_vshare year_zero if  year_zero>=-4000 & year_zero<=4000, msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
		(line yhatm1 year_zero if year_zero<0 & year_zero>=-4000, clcol(black))	///
		(line yhatm1 year_zero if year_zero>=0 & year_zero<=4000, clcol(black)), ///
			yline(0 100, lw(thin) lc(gs14)) xline(0, lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 100)) ylabel(, angle(h) labsize(vsmall) nogrid) ///
			xlab(-3650 "-10" -2920 "-8" -2190 "-6" -1460 "-4" -730 "-2" 0 "0"	///
				  730 "2" 1460 "4" 2190 "6" 2920 "8" 3650 "10" , labsize(vsmall) format(%tdCCYY)) ///
			xtitle("Years from reform", size(small) col(black))	ytitle("Democratic % of Total Vote", size(vsmall))	///
			title("Democratic Vote Share", size(small) col(black) box bexpand) note("") legend(off) name(combined_demshare, replace)

	levelsof group, local(levels)
	foreach x in `levels' {
		local y = subinstr("`x'"," ","",.) 
		* trim outliers for graphing purposes
		
		di "`x'"
		qui summ reform if group=="`x'"
		local k = r(min)
		if "`x'" == "Rhode Island"  {
			tw (scatter dem_vshare date1 if group=="`x'", msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci dem_vshare date1 if category==2 & group=="`x'", clcol(black))	///
				(lpolyci dem_vshare date1 if category==1 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14)) xline(`k', lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) fxsize(35) yscale(range(0 100)) ylabel(0(25)100, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Virginia" {
			tw (scatter dem_vshare date1 if group=="`x'", msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci dem_vshare date1 if category==2 & group=="`x'", clcol(black))	///
				(lpolyci dem_vshare date1 if category==1 & group=="`x'", clcol(black)) ///
				(lpolyci dem_vshare date1 if category==0 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14)) xline(-47361 -39800, lw(thin) lp(dash) lc(black))				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 100)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else if "`x'" == "Louisiana" {
			tw (scatter dem_vshare date1 if group=="`x'", msy(o) jitter(.5) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci dem_vshare date1 if category==1 & group=="`x'", clcol(black))	///
				(lpolyci dem_vshare date1 if category==0 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14))	xline(`k', lw(thin) lp(dash) lc(black))			///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 100)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}
		else {
			tw (scatter dem_vshare date1 if group=="`x'", msy(o) jitter(.8) mc(gs13) msize(vsmall) mlw(vvvthin) mlc(gs12) )	///
				(lpolyci dem_vshare date1 if category==0 & group=="`x'", clcol(black)), ///
				yline(0 100, lw(thin) lc(gs14)) 				///
				graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) yscale(range(0 100)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
					title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
		}	

	}

restore
graph combine RhodeIsland Virginia Louisiana AllOtherStates, cols(4) imargin(none) ///
		graphreg(col(white)) xcommon l1title("Democratic % of Total Vote", size(vsmall)) 	///
		title("Democratic Vote Share", size(small) col(black)) name(antebellum_states_party, replace)
****************	Party Vote Share (early Republic)	************************
*** Load the Early Republic voting file
use "Data\Early-Republic-Votes-All-States.dta",  clear

*** Set the panel shape to the data. The basic unit is the place/office. 
xtset newID date1
egen state1	= group(icpsrstate)

*** Merge in reduced suffrage database. This will be used for supplemental material.
merge m:1 icpsrstate year using "Data\Suffrage-Reduced.dta", gen(merge1)
keep if merge1==3
drop merge1

gen category_prop_tax = 0 if whnb_property_effective==0 & whnb_taxpayer==0
replace category_prop_tax = 1 if whnb_taxpayer==1 
replace category_prop_tax = 2 if whnb_property_effective==1 

capture label drop category_prop_tax
label define category_prop_tax 0 "Residency"
label define category_prop_tax 1 "Tax", add
label define category_prop_tax 2 "Property", add
label values category_prop_tax category_prop_tax

*** When did suffrage reform go into effect?
gen reform 		= . 
replace reform	= -57351 if state=="Maryland" 
replace reform	= -51683 if state=="Connecticut" 
replace reform	= -50344 if state=="New York" 
replace reform	= -50618 if state=="Massachusetts" 
replace reform	= -55563 if state=="New Jersey" 
replace reform	= -54434 if state=="South Carolina" 
replace reform	= -61197 if state=="Delaware" 

*** Index which states made a substantial change
gen refState	= (state=="Maryland" | state=="Connecticut" | state=="New York"		///
					| state=="Massachusetts" | state=="New Jersey" | state=="South Carolina" 	///
					| state=="Delaware")

gen category 	 = 1 if (date1<-57351) & icpsrstate==52 // Amendment passed second time on 23rd Dec 1803
replace category = 1 if (date1<-51683) & icpsrstate==1 	// Constitution ratified on first Monday of Oct 1818. In Nov. 1817 a modification of the existing election law was passed, repealing the "stand-up" law. A constitutional convention would be called in 1818 on a broad franchise.
replace category = 1 if (date1<-50344) & icpsrstate==13	// Constitution ratified in January 1822 and went into effect on Dec 31 1822. Suffrage went into effect 1st Monday of March 1822
replace category = 2 if (date1<-50344) & icpsrstate==13 & (office=="Governor" | office=="State Senate") // Constitution ratified in January 1822 and went into effect on Dec 31 1822. Suffrage went into effect 1st Monday of March 1822
replace category = 1 if (date1<-50618) & icpsrstate==3 	// Constitutional amendments ratified in April/May of 1821. Presented to General Court on May 31 and certified May 24
replace category = 1 if (date1<-55563) & icpsrstate==12	// Statute altering qualifications enacted on Nov 16 - "from and after the passing of this act."
replace category = 2 if (date1<-54434) & icpsrstate==48	// Constitutional amendment ratified on December 19, 1810.
replace category = 1 if (date1<-61197) & icpsrstate==11	// Constitution goes into effect on June 12, 1792.
replace category = 1 if (date1<-39800) & icpsrstate==40 // Constitution went into effect on January 12, 1851
replace category = 2 if (date1<-47361) & icpsrstate==40 // Constitution ratified and went into effect in April/May 1830
replace category = 2 if (date1<-42643) & icpsrstate==5	// New (non-Dorrite) constitution was proclaimed in January and went into effect in May 1843. But for elections went into effect in April.
replace category = 1 if (date1>=-42643) & icpsrstate==5	// Constitution went into effect in May 1843
replace category = 1 if (date1<-41637) & icpsrstate==45	// Constitution went into effect in January 1846
replace category = 0 if category==.

*** Generate time variables
gen time = year-1787
gen time_2 = time^2
gen decade = int(year/10)*10

*** Easiest way to look at party vote share in early republic is just the aggregate
*** Democratic-Republican share of the two-party vote share. This leaves a lot out
*** since many elections no party or only one party can be identified. 

gen dem_vshare		= round(republican/total*100,0.01)
gen fed_vshare		= round(federalist/total*100,0.01)

gen fed_vshare2		= round(fed_vshare/(fed_vshare+dem_vshare)*100,0.01)
gen dem_vshare2		= round(dem_vshare/(fed_vshare+dem_vshare)*100,0.01)

*** Same analysis as for antebellum. 
eststo dem_early: xtreg dem_vshare2 i.category i.decade if level==2, fe cluster(icpsrstate)
estadd local ctrls "Yes"
estadd local fixed "Yes"

*** Specific enfranchising states
levelsof state if refState==1, local(reform)
foreach x in `reform' {
	local y = subinstr("`x'", " ","",.)
	qui summ year if category==0 & state=="`x'"
	local k = r(min)
	local year_1 = `k'-5
	local year_2 = `k'+5
	
	eststo ref_`y': xtreg dem_vshare2 i.category if level==2 & refState==1 & state=="`x'" & year>=`year_1' & year<=`year_2', fe robust
	margins, over(category)
	marginsplot, recast(scatter) xsc(reverse) name(ref_`y', replace) ///
		plotopts(lw(thin) mlc(black) mcol(white)) ciopts(lw(thin) lc(black))	///
		graphreg(col(none)) ylabel(, nogrid angle(h) labsize(vsmall)) ytitle("")	///
		xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vsmall))	title("`x'", size(small) col(black) )	
}


gen group 		= state
replace group	= "No Change" if refState==0 
	
levelsof group if group!="Delaware", local(levels)
foreach x in `levels' {
	local y = subinstr("`x'"," ","",.) 

	qui summ reform if group=="`x'"
	local k = r(min)
	if "`x'" == "New York"  {
		tw (scatter dem_vshare2 date1 if group=="`x'" , msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci dem_vshare2 date1 if category==2 & group=="`x'" & year!=1805, clcol(black))	///
			(lpolyci dem_vshare2 date1 if category==1 & group=="`x'", clcol(gs9))	///
			(lpolyci dem_vshare2 date1 if category==0 & group=="`x'" & id1!=".governor" & id1!=".MSS", clcol(gs9))	///
			(lpolyci dem_vshare2 date1 if category==0 & group=="`x'" & (id1==".governor" | id1==".MSS"), clcol(black)), ///
			xline(`k', lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}
	else if "`x'" == "South Carolina" {
		tw (scatter dem_vshare2 date1 if group=="`x'" , msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci dem_vshare2 date1 if category==2 & group=="`x'", clcol(black))	///
			(lpolyci dem_vshare2 date1 if category==0 & group=="`x'", clcol(black)), ///
			xline(`k', lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}
	else if "`x'" == "No Change" {
		tw (scatter dem_vshare2 date1 if group=="`x'" , msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci dem_vshare2 date1 if category==2 & group=="`x'", clcol(black))	///
			(lpolyci dem_vshare2 date1 if category==0 & group=="`x'", clcol(gs9)), ///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}
	else if "`x'" == "Connecticut" { 
		tw (scatter dem_vshare2 date1 if group=="`x'" & year>=1800, msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci dem_vshare2 date1 if category==1 & group=="`x'"  & year>=1800, clcol(gs9))	///
			(lpolyci dem_vshare2 date1 if category==0 & group=="`x'"  & year>=1800, clcol(gs9)), ///
			xline(`k', lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}	
	else {
		tw (scatter dem_vshare2 date1 if group=="`x'", msy(o) jitter(.5) mc(gs15) msize(vsmall) mlw(vvvthin) mlc(gs14) )	///
			(lpolyci dem_vshare2 date1 if category==1 & group=="`x'", clcol(gs9))	///
			(lpolyci dem_vshare2 date1 if category==0 & group=="`x'", clcol(gs9)), ///
			xline(`k', lw(thin) lp(dash) lc(black))				///
			graphregion(color(white) margin(tiny)) plotregion(lcolor(black)) ylabel(none, angle(h) labsize(vsmall) nogrid) xlab(none, labsize(vsmall) format(%tdCCYY)) ///
				title("`x'", size(small) col(black) box bexpand) note("") legend(off) name("`y'", replace)
	}	

}


********************************************************************************
**************	 Create Tables and Combine Figures 	  **************************
********************************************************************************
****************				Main Text 				************************

*** Table 6 - Effect of franchise qualifications on turnout and Republican/Democratic vote share
esttab tn1 tn2 dem_antebellum dem_early using "Tables/Table-6.tex", se(a2)  label 	///
	title(Effect of Franchise Qualifications on Turnout and Republican/Democratic Vote Share) 	///
	drop( _cons 0.pres_election 1.pres_election 1790.decade 1800.decade 1810.decade 1820.decade 1830.decade 1840.decade 1850.decade 1860.decade 0.category gained lost) nonumbers 	coeflabels(1.category "Medium Threshold ($\beta_{1}$)" 2.category "High Threshold ($\beta_{2}$)")	///
	mgroups("Turnout" 	"Turnout, Std." "Democratic Vote Share" , pattern(1 1 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("1823-1858" "1823-1858" "1823-1858" "1795-1825") nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(ctrls fixed N_g N, fmt(%9.0g) label("Additional controls" "County fixed effects" "Counties" "N")) b(a3) 						///
	nolines prehead(\begin{table}[hbt!]\centering	\caption{@title} \label{tab:6} \begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \end{tabular} \floatnote{Standard errors clustered at the state leve. Controls for decade and presidential election year included in turnout models, and for change in territory in standardized turnout model. Early Republic analysis is at the county level.} \end{table}) substitute(\_ _) tex   replace
	
*** Figure 6 - Antebellum turnout, Democratic vote share, and suffrage reform.
graph combine combined_turnout combined_demshare, imargin(tiny) col(2) graphreg(col(white)) ycommon  name(combined_1, replace)
graph combine antebellum_states_turnout antebellum_states_party combined_1, imargin(tiny) row(3) graphreg(col(white))	///
		note("Dashed vertical lines mark effective reform date. Turnout graphs trimmed at 125% of adult white men.", size(vsmall))
graph export "Figures/Figure-6.pdf", replace 


****************			Supplemental Material			********************
*** Supplemental Table 10 - Effect of Franchise Qualifications on Turnout in VA, RI, and LA
esttab tn3 tn4 tn5 using "Tables/Supplemental/Supplemental-Table-10.tex", se(a2)  label 	///
	title(Effect of Franchise Qualifications on Turnout) 	///
	drop( _cons 0.pres_election 1.pres_election 0.category) nonumbers 	coeflabels(1.category "Medium Threshold ($\beta_{1}$)" 2.category "High Threshold ($\beta_{2}$)")	///
	mgroups("Virginia" "Rhode Island" "Louisiana" , pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("1823-1858" "1823-1858" "1823-1858" "1795-1825") nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(fixed N_g N, fmt(%9.0g) label("County fixed effects" "Counties" "N")) b(a3) 						///
	nolines prehead(\begin{table}[hbt!]\centering	\caption{@title} \label{tab:A10} \begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \end{tabular} \floatnote{Robust standard errors in parentheses. } \end{table}) substitute(\_ _) tex   replace	

*** Supplemental Table 13 - Effect of Franchise Qualifications on Democratic Vote Share in VA, RI, and LA
esttab dem_va dem_ri dem_la using "Tables/Supplemental/Supplemental-Table-13.tex", se(a2)  label 	///
	title(Effect of Franchise Qualifications on Democratic Vote Share) 	///
	drop( _cons  0.category ) nonumbers 	coeflabels(1.category "Medium Threshold ($\beta_{1}$)" 2.category "High Threshold ($\beta_{2}$)")	///
	mgroups("Virginia" "Rhode Island" "Louisiana" , pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span )         ///
	mtitles("1823-1858" "1823-1858" "1823-1858" "1795-1825") nogaps nodepvars nostar compress noconstant nonotes	 		///
	stats(ctrls fixed N_g N, fmt(%9.0g) label("Additional controls" "County fixed effects" "Counties" "N")) b(a3) 						///
	nolines prehead(\begin{table}[hbt!]\centering	\caption{@title} \label{tab:A13} \begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \end{tabular} \floatnote{Robust standard errors in parentheses. } \end{table}) substitute(\_ _) tex   replace	
	
*** Supplemental Table 18 - Alternative Specification of Franchise Qualifications
esttab suppl_tax_prop_1 suppl_tax_prop_2 suppl_tax_prop_3 using "Tables/Supplemental/Supplemental-Table-18.tex", se(a2) label 	///
	drop(0.category_prop_tax 0.pres_election 1.pres_election 1820.decade 1830.decade 1840.decade 1850.decade 1860.decade _cons gained lost)  ///
	title(Effect of Property and Taxpaying Qualifications on Turnout and Democratic Vote Share) 	///
	mtitles("\shortstack{Turnout\\(1823-1860)}" "\shortstack{Standardized Turnout\\(1823-1860)}" "\shortstack{Democratic Vote\\Share}") nogaps nodepvars	///
	nostar compress nonumbers  ///
	stats(N N_g, fmt(%9.0g %9.0f) label("N" "Counties" )) b(a3) ///
	prehead(\begin{table}[hbt!]\centering	\caption{@title} \label{tab:A18} \begin{tabular}{l*{@M}{c}} \toprule)		///		
	posthead(\midrule)  prefoot(\midrule) ///
	postfoot(\bottomrule \end{tabular} \floatnote{County FE in all models. Standard errors clustered at state-level. Controls for decade and presidential election year included in all turnout models; controls for change in county territory included in standardized turnout model.} \end{table}) substitute(\_ _) tex   replace

*** The following figures are not included in the supplemental material. They show the estimated change
*** in Democratic (or equivalent) voting in the early Republic. 
graph combine Maryland NewJersey  Connecticut Massachusetts NewYork SouthCarolina NoChange, cols(4) imargin(none) ///
		graphreg(col(white)) ycommon xcommon l1title("Republican Share of Two Party Vote", size(vsmall)) 	///
		note("States with initially high qualifications shown in black, medium or low qualifications in gray.", size(vsmall)) 
graph combine ref_Maryland ref_NewJersey ref_SouthCarolina ref_Connecticut ref_Massachusetts ref_NewYork , cols(3) imargin(none) ///
		graphreg(col(white)) ycommon xcommon l1title("Predicted Republican Share of Two Party Vote", size(vsmall)) 	///
		title("Franchise Qualifications and Republican Voting in the Early Republic", col(black) size(small))
